package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.CstCollectionRegistration;
import com.ruoyi.system.service.ICstCollectionRegistrationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 收款登记Controller
 * 
 * @author zjw
 * @date 2023-01-04
 */
@RestController
@RequestMapping("/cst/registration")
public class CstCollectionRegistrationController extends BaseController
{
    @Autowired
    private ICstCollectionRegistrationService cstCollectionRegistrationService;

    /**
     * 查询收款登记列表
     */
    @PreAuthorize("@ss.hasPermi('cst:registration:list')")
    @GetMapping("/list")
    public TableDataInfo list(CstCollectionRegistration cstCollectionRegistration)
    {
        startPage();
        List<CstCollectionRegistration> list = cstCollectionRegistrationService.selectCstCollectionRegistrationList(cstCollectionRegistration);
        return getDataTable(list);
    }

    /**
     * 导出收款登记列表
     */
    @PreAuthorize("@ss.hasPermi('cst:registration:export')")
    @Log(title = "收款登记", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CstCollectionRegistration cstCollectionRegistration)
    {
        List<CstCollectionRegistration> list = cstCollectionRegistrationService.selectCstCollectionRegistrationList(cstCollectionRegistration);
        ExcelUtil<CstCollectionRegistration> util = new ExcelUtil<CstCollectionRegistration>(CstCollectionRegistration.class);
        util.exportExcel(response, list, "收款登记数据");
    }

    /**
     * 获取收款登记详细信息
     */
    @PreAuthorize("@ss.hasPermi('cst:registration:query')")
    @GetMapping(value = "/{collectionId}")
    public AjaxResult getInfo(@PathVariable("collectionId") Long collectionId)
    {
        return success(cstCollectionRegistrationService.selectCstCollectionRegistrationByCollectionId(collectionId));
    }

    /**
     * 新增收款登记
     */
    @PreAuthorize("@ss.hasPermi('cst:registration:add')")
    @Log(title = "收款登记", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CstCollectionRegistration cstCollectionRegistration)
    {
        return toAjax(cstCollectionRegistrationService.insertCstCollectionRegistration(cstCollectionRegistration));
    }

    /**
     * 修改收款登记
     */
    @PreAuthorize("@ss.hasPermi('cst:registration:edit')")
    @Log(title = "收款登记", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CstCollectionRegistration cstCollectionRegistration)
    {
        return toAjax(cstCollectionRegistrationService.updateCstCollectionRegistration(cstCollectionRegistration));
    }

    /**
     * 删除收款登记
     */
    @PreAuthorize("@ss.hasPermi('cst:registration:remove')")
    @Log(title = "收款登记", businessType = BusinessType.DELETE)
	@DeleteMapping("/{collectionIds}")
    public AjaxResult remove(@PathVariable Long[] collectionIds)
    {
        return toAjax(cstCollectionRegistrationService.deleteCstCollectionRegistrationByCollectionIds(collectionIds));
    }
}
